package cn.rongdao.jrkabao.ui.main.mainfragment.loanfragment.uicomponent;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mifengkong.frtools.util.FRImageLoad;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.main.ProductListBean;


/**
 * Created by jack on 17/5/10
 */

public class ItemMainUIComponent extends RelativeLayout {

    private ImageView mIvTag;
    private View mFootrView;

    public ItemMainUIComponent(Context context) {
        super(context);
    }

    public ItemMainUIComponent(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ItemMainUIComponent(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private ImageView ivAvatar;
    private TextView tvTitle;
    private TextView tvContent;
    private TextView tvAmount;
    private String minAmountStr = "";
    private String maxAmountStr = "";

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        ivAvatar = (ImageView) findViewById(R.id.im_iv_avatar);
        tvTitle = (TextView) findViewById(R.id.im_tv_title);
        tvContent = (TextView) findViewById(R.id.im_tv_content);
        tvAmount = (TextView) findViewById(R.id.im_iv_amount);
        mIvTag = (ImageView) findViewById(R.id.im_iv_tag);
        mFootrView = findViewById(R.id.im_center_view);
    }


    public void setContent(ProductListBean data) {
        FRImageLoad.loadImage(data.getOrg_pic(), ivAvatar);
        FRImageLoad.loadImage(data.getIs_hot_pic(), mIvTag);
        if ("1".equals(data.getIs_apply())) {
            tvContent.setText("查看申请");
            tvContent.setTextColor(getResources().getColor(R.color.cb0b0b0));
            tvContent.setBackgroundDrawable(getResources().getDrawable(R.drawable.graybg_100radius));
        } else {
            tvContent.setText("立即申请");
            tvContent.setTextColor(getResources().getColor(R.color.cfc494a));
            tvContent.setBackgroundDrawable(getResources().getDrawable(R.drawable.redbg_100_border));
        }
        tvTitle.setText(data.getOrg_name());
        try {

            int minAmount = Integer.parseInt(data.getGrade_scope_lowest());
            int maxAmount = Integer.parseInt(data.getGrade_scope_highest());
            if (minAmount / 10000 > 0) {
                minAmountStr = minAmount / 10000 + "万";
            } else {
                minAmountStr = data.getGrade_scope_lowest();
            }
            if (maxAmount / 10000 > 0) {
                maxAmountStr = maxAmount / 10000 + "万";
            } else {
                maxAmountStr = data.getGrade_scope_highest();
            }
            tvAmount.setText(TextUtils.concat(minAmountStr, " - ", maxAmountStr).toString());
        } catch (Exception e) {

        }

    }


    public void getCurrentPosition(int count, int position) {
        if (position != count - 1)
            mFootrView.setVisibility(VISIBLE);
    }
}